package com.jysz.certificate.persistence.model.cm;

import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;

import com.jysz.certificate.persistence.enums.CertificationType;
import com.jysz.certificate.persistence.enums.CopyOfCertificationImporting;
import com.jysz.certificate.persistence.model.system.Brand;
import com.jysz.certificate.persistence.model.system.Financial;
import com.jysz.certificate.persistence.model.system.Shop;
import com.jysz.certificate.persistence.model.system.User;
import com.jysz.webcore.ssh.entity.AbstractBaseEntity;

/**
 * 合格证对象
 * @author <a href="mailto:javaengine@outlook.com">Kaca Rich</a>
 *
 */
@Entity
@Table(name = "cm_certification_")
@org.hibernate.annotations.Entity
public class Certification  extends AbstractBaseEntity<Long>  {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Shop shop;//销售店
	private Financial financial;//金融机构
	private Brand brand;//主机厂<品牌>
	private String certificationNum;//合格证号
//	private User user;//创建人
	private Date departDate;//发车日期
	private String motorcycleType;// 车型
	private String chassis;// 车架号
	private String engine;//发动机号
	private String orderNumber;//  订单号
	private Double supplyPrice;// 供货价begin
	private String draft;//  汇票号
	private Date draftBeginDate;//汇票号开始时间
	private Date draftEndDate;//汇票号结束时间
	private Date goingOutDate;// 出门日
	private Date scheduledDate;//预计到店日
	private Date createDate;//创建日期
//	private Date receiveDate;//确认收证时间
	private Date buluDate;//补录日期 
	private Date leaveDate;//释放时间
	private Release release;//释放单
	private User releaseUser;//释放人
	/** 释放单号*/
	private String releaseNum;
	private Date applyReleaseDate;//申请出库日期
	private Date warehouseDate;//入库日期warehouseDate 
	private Date applicationWarehouseDate;//申请入库日期
	private String theAddress;//二网地址
	private String remarks;//备注
	private String batchNumber;//导入批次号
	private Boolean change;//变更运输地的标记
	private CertificationType state;//合格证状态
	private CopyOfCertificationImporting cmImporting;//合格证是否为导入标示
	
	private Set<CertificateRenew> certificateRenews; //关联换证单，多对多。。
	private CertificateRenew certificateRenew; //关联换成单，如果为NULL未经过换证入库。
	
	
	private String copyShow;//复制二网地址，只用来在页面中显示
	
	private Date applyTheDate;//申请出库日期
	
	@Transient
	public String getCopyShow() {
		return copyShow;
	}
	public void setCopyShow(String copyShow) {
		this.copyShow = copyShow;
	}
	@Column(name = "_bulu_date")
	public Date getBuluDate() {
		return buluDate;
	}
	public void setBuluDate(Date buluDate) {
		this.buluDate = buluDate;
	}
	@Column(name = "_batch_number",columnDefinition="varchar(255)")
	public String getBatchNumber() {
		return batchNumber;
	}
	public void setBatchNumber(String batchNumber) {
		this.batchNumber = batchNumber;
	}
	@Column(name = "_remarks",columnDefinition="varchar(255)")
	public String getRemarks() {
		return remarks;
	}
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	@Column(name = "_change",columnDefinition="int(11)")
	public Boolean getChange() {
		return change == null ? false : change;
	}
	public void setChange(Boolean change) {
		this.change = change;
	}

	@ManyToOne(fetch = FetchType.LAZY)  
	@JoinColumn(name = "_financial_id",columnDefinition="bigint(20)") 
	public Financial getFinancial() {
		return financial;
	}
	@ManyToOne(fetch = FetchType.LAZY)  
	@JoinColumn(name = "_shop_id",columnDefinition="bigint(20)") 
	public Shop getShop() {
		return shop;
	}
	@ManyToOne(fetch = FetchType.LAZY)  
	@JoinColumn(name = "_brand_id",columnDefinition="bigint(20)") 
	public Brand getBrand() {
		return brand;
	}

	
	public void setShop(Shop shop) {
		this.shop = shop;
	}
	
	public void setFinancial(Financial financial) {
		this.financial = financial;
	}
	
	public void setBrand(Brand brand) {
		this.brand = brand;
	}
	@Column(name = "_certificationNum", unique = true,columnDefinition="varchar(255)")
	public String getCertificationNum() {
		return certificationNum;
	}
	public void setCertificationNum(String certificationNum) {
		if(StringUtils.isNotBlank(certificationNum))
			certificationNum = certificationNum.toUpperCase();
		this.certificationNum = certificationNum;
	}
	@Column(name = "_departDate")
	public Date getDepartDate() {
		return departDate;
	}
	public void setDepartDate(Date departDate) {
		this.departDate = departDate;
	}
	@Column(name = "_motorcycleType",columnDefinition="varchar(255)")
	public String getMotorcycleType() {
		return motorcycleType;
	}
	public void setMotorcycleType(String motorcycleType) {
		this.motorcycleType = motorcycleType;
	}
	@Column(name = "_chassis", nullable = false, unique = true,columnDefinition="varchar(255)")
	public String getChassis() {
		return chassis;
	}
	public void setChassis(String chassis) {
		if(StringUtils.isNotBlank(chassis))
			chassis = chassis.toUpperCase();
		this.chassis = chassis;
	}
	@Column(name = "_engine",columnDefinition="varchar(255)")
	public String getEngine() {
		return engine;
	}
	public void setEngine(String engine) {
		this.engine = engine;
	}
	@Column(name = "_orderNumber",columnDefinition="varchar(255)")
	public String getOrderNumber() {
		return orderNumber;
	}
	public void setOrderNumber(String orderNumber) {
		this.orderNumber = orderNumber;
	}
	@Column(name = "_supplyPrice",columnDefinition="numeric(9,2)")
	public Double getSupplyPrice() {
		return supplyPrice;
	}
	public void setSupplyPrice(Double supplyPrice) {
		this.supplyPrice = supplyPrice;
	}
	@Column(name = "_draft",columnDefinition="varchar(255)")
	public String getDraft() {
		return draft;
	}
	public void setDraft(String draft) {
		this.draft = draft;
	}
	@Column(name = "_draftBeginDate")
	public Date getDraftBeginDate() {
		return draftBeginDate;
	}
	public void setDraftBeginDate(Date draftBeginDate) {
		this.draftBeginDate = draftBeginDate;
	}
	@Column(name = "_draftEndDate")
	public Date getDraftEndDate() {
		return draftEndDate;
	}
	public void setDraftEndDate(Date draftEndDate) {
		this.draftEndDate = draftEndDate;
	}
	@Column(name = "_goingOutDate")
	public Date getGoingOutDate() {
		return goingOutDate;
	}
	public void setGoingOutDate(Date goingOutDate) {
		this.goingOutDate = goingOutDate;
	}
	@Column(name = "_scheduledDate")
	public Date getScheduledDate() {
		return scheduledDate;
	}
	public void setScheduledDate(Date scheduledDate) {
		this.scheduledDate = scheduledDate;
	}
	@Column(name = "_createDate")
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
//	@Column(name = "_receiveDate")
//	public Date getReceiveDate() {
//		return receiveDate;
//	}
//	public void setReceiveDate(Date receiveDate) {
//		this.receiveDate = receiveDate;
//	}
	@Column(name = "_leaveDate")
	public Date getLeaveDate() {
		return leaveDate;
	}
	public void setLeaveDate(Date leaveDate) {
		this.leaveDate = leaveDate;
	}
	@Column(name = "_cmImporting",columnDefinition="int(11)")
	@Enumerated(EnumType.ORDINAL)
	public CopyOfCertificationImporting getCmImporting() {
		return cmImporting;
	}
	public void setCmImporting(CopyOfCertificationImporting cmImporting) {
		this.cmImporting = cmImporting;
	}
	
	@Column(name = "_state",columnDefinition="int(11)")
	@Enumerated(EnumType.ORDINAL)
	public CertificationType getState() {
		return state;
	}
	public void setState(CertificationType state) {
		this.state = state;
	}
	
	@ManyToOne(targetEntity = Release.class, cascade=CascadeType.REFRESH)
	@JoinColumn(name="_release_id", insertable=true, updatable=true) 
	public Release getRelease() {
		return release;
	}
	public void setRelease(Release release) {
		this.release = release;
	}
	
	@ManyToOne(fetch = FetchType.LAZY,cascade=CascadeType.REFRESH)  
	@JoinColumn(name = "_release_user",insertable=true, updatable=true,columnDefinition="bigint(20)")
	public User getReleaseUser() {
		return releaseUser;
	}
	public void setReleaseUser(User releaseUser) {
		this.releaseUser = releaseUser;
	}
	@Column(name= "_release_num",nullable=true,columnDefinition="varchar(255)")
	public String getReleaseNum() {
		return releaseNum;
	}

	public void setReleaseNum(String releaseNum) {
		this.releaseNum = releaseNum;
	}
	@Column(name = "_warehouseDate")
	public Date getWarehouseDate() {
		return warehouseDate;
	}
	public void setWarehouseDate(Date warehouseDate) {
		this.warehouseDate = warehouseDate;
	}
	@Column(name = "_applyReleaseDate")
	public Date getApplyReleaseDate() {
		return applyReleaseDate;
	}
	public void setApplyReleaseDate(Date applyReleaseDate) {
		this.applyReleaseDate = applyReleaseDate;
	}
	@Column(name = "_applicationWarehouseDate")
	public Date getApplicationWarehouseDate() {
		return applicationWarehouseDate;
	}
	public void setApplicationWarehouseDate(Date applicationWarehouseDate) {
		this.applicationWarehouseDate = applicationWarehouseDate;
	}
	@Column(name = "_theAddress",columnDefinition="varchar(255)")
	public String getTheAddress() {
		return theAddress;
	}
	public void setTheAddress(String theAddress) {
		this.theAddress = theAddress;
	}

	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)  
	@JoinColumn(name = "_certificate_renew_id",columnDefinition="bigint(20)")
	public CertificateRenew getCertificateRenew() {
		return certificateRenew;
	}
	public void setCertificateRenew(CertificateRenew certificateRenew) {
		this.certificateRenew = certificateRenew;
	}
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "rs_cm_certificate_renew_cm_certification_", joinColumns = @JoinColumn(name = "_certification_id"), inverseJoinColumns = @JoinColumn(name = "_certificate_renew_id"))
	public Set<CertificateRenew> getCertificateRenews() {
		return certificateRenews;
	}
	
	public void setCertificateRenews(Set<CertificateRenew> certificateRenews) {
		this.certificateRenews = certificateRenews;
	}
	@Column(name = "_applyTheDate")
	public Date getApplyTheDate() {
		return applyTheDate;
	}
	public void setApplyTheDate(Date applyTheDate) {
		this.applyTheDate = applyTheDate;
	}

	/**begin properties column constan**/
	public static final String ID = "id";
	public static final String SHOP = "shop";
	public static final String BRAND = "brand";
	public static final String STATE = "state";
	public static final String DEPARTDATE = "departDate";
	public static final String COLUMN_FINANCIAL = "financial";
	/**end properties column constan**/

}
